package com.zd.kids.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.TextView;

import com.blankj.utilcode.util.KeyboardUtils;
import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.SpanUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.hyy.libray.presenter.IBasePresenter;
import com.hyy.libray.ui.activity.BaseActivity;
import com.zd.kids.R;
import com.zd.kids.common.UserInfoConfig;
import com.zd.kids.net.CustomObserver;
import com.zd.kids.net.HttpMethod;
import com.zd.kids.ui.view.SendEmailPopupWindow;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class JoinClassComputerActivity extends BaseActivity {

    @BindView(R.id.tv_psw)
    TextView tvPsw;

    @BindView(R.id.tv_content_1)
    TextView tvWebPath;


    public static final String PSW_KEY = "PSW_KEY";

    public static final String WEB_PATH_KEY = "WEB_PATH_KEY";

    /**
     * z
     * 获取布局文件地址
     */
    @Override
    public int getLayoutResId() {
        return R.layout.activity_join_class_computer;
    }

    /**
     * 初始化布局
     */
    @Override
    public void initView() {

        initTitle(getString(R.string.go_class_process));

        String pswStr = getIntent().getStringExtra(PSW_KEY);
        String webPath = getIntent().getStringExtra(WEB_PATH_KEY);

        tvWebPath.setText(webPath);

        SpanUtils.with(tvPsw)
                .append("1." + getString(R.string.your_name))
                .setForegroundColor(0xFF555555)
                .append(UserInfoConfig.getInstance().getName())
                .setForegroundColor(0xFF555555)
                .append("\n")
                .append("2." + getString(R.string.my_room_num))
                .setForegroundColor(0xFF555555)
                .append(pswStr)
                .setForegroundColor(0xFF9124A3)
                .create() ;


    }

    /**
     * 获取Presenter，不用MVP，可以为空
     *
     * @return
     */
    @Override
    protected IBasePresenter onBasePresenter() {
        return null;
    }

   private SendEmailPopupWindow mSendEmailPopupWindow;

    @OnClick({R.id.tv_send_email, R.id.tv_help})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_send_email:
                if (mSendEmailPopupWindow == null) {
                    mSendEmailPopupWindow = new SendEmailPopupWindow(this, new SendEmailPopupWindow.ConfirmCallBack() {
                        @Override
                        public void confrimCallBack(String email) {
                            mSendEmailPopupWindow.dismiss();
                            sendEMail(email);
                        }
                    });
                }
                mSendEmailPopupWindow.showView();
                break;
            case R.id.tv_help:
                Intent intent = new Intent(this, HelpActivity.class);
                startActivity(intent);
                break;
        }
    }

    private void sendEMail(String email) {
        showLoading();
        Map map = new HashMap();
        map.put("scenes", "1");
        map.put("email", email);
        HttpMethod.getIntence()
                .sendMail(map, new CustomObserver<String>(this) {
                    @Override
                    public void onSuccess(String commonStatusDataBean) {
                        disLoading();
                        ToastUtils.showLong("已發送，請註意查收您的郵箱");
                    }

                    @Override
                    public void onError(String errorCode) {
                        disLoading();
                    }
                });
    }

}
